package com.qyhl.webtv.module_news.luckydraw.detail;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.LuckDrawInfoBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by Administrator on 2018/6/14.
 */

public class LuckDrawWinnerDetailModel implements LuckDrawWinnerDetailContract.LuckDrawWinnerDetailModel {
    private LuckDrawWinnerDetailPresenter mPresenter;

    public LuckDrawWinnerDetailModel(LuckDrawWinnerDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void queryInfo(String phoneNum, final String lastId) {

        EasyHttp.get(NewsUrl.QUERY_LUCK_DRAW_INFO)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("phoneNum", phoneNum)
                .params("lastId", lastId)
                .execute(new SimpleCallBack<List<LuckDrawInfoBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202 ) {
                            if ("0".equals(lastId)) {
                                mPresenter.setQueryInfoError(2, "暂无任何中奖信息！");
                            }else{
                                mPresenter.setQueryInfoError(3, "没有更多中奖信息！");
                            }
                        } else {
                            if ("0".equals(lastId)) {
                                mPresenter.setQueryInfoError(4, "查询失败！");
                            }else{
                                mPresenter.setQueryInfoError(5, "查询失败！");
                            }
                        }
                    }

                    @Override
                    public void onSuccess(List<LuckDrawInfoBean> luckDrawInfoBeans) {
                        if (luckDrawInfoBeans.size() > 0) {
                            if ("0".equals(lastId)) {
                                mPresenter.setQueryInfoSuccess(false, luckDrawInfoBeans);
                            }else{
                                mPresenter.setQueryInfoSuccess(true, luckDrawInfoBeans);
                            }
                        } else  {
                            if ("0".equals(lastId)) {
                                mPresenter.setQueryInfoError(2, "暂无任何中奖信息！");
                            }else{
                                mPresenter.setQueryInfoError(3, "没有更多中奖信息！");
                            }
                        }
                    }
                });


    }
}
